package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppMingXiTx;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author anxiang
 * @version 1.0.0
 * @ClassName AppMingXiTxDao.java
 * @Description TODO
 * @createTime 2021年11月02日 15:04:00
 */
@Repository
public class AppMingXiTxDao extends BaseDao<AppMingXiTx>{

    public void saveOrUpdate(AppMingXiTx appMingXiTx) {
        if (appMingXiTx.getId() == null || appMingXiTx.getId() == 0) {
            appMingXiTx.setId(this.add(appMingXiTx));
        } else {
            this.update(appMingXiTx);
        }
    }

    public List<AppMingXiTx> findList(Integer userid, SplitPageBean splitPageBean) {
        List<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder();
        str.append("select * from app_mingxi_tx where 1=1 ");
        if (StringEx.isNotNull(userid)) {
            str.append(" and userid = ? ");
            list.add(userid);
        }
        str.append(" order by createtime desc ");
        String sql = str.toString();
        return this.queryList(sql, list, AppMingXiTx.class, splitPageBean);
    }

    public List<AppMingXiTx> total(Map<String, Object> params) {
        List<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder();
        str.append("select * from app_mingxi_tx where 1=1 ");

        if(params.containsKey("today") && StringEx.isNotNull(params.get("today"))) {
            str.append(" and to_days(createtime) = to_days(now())");
        }
        String sql = str.toString();
        return this.queryList(sql, list, AppMingXiTx.class);
    }

}